package com.search.controller;

import com.common.exception.BizCodeEnum;
import com.common.to.es.SkuEsModel;
import com.common.utils.R;
import com.search.service.impl.ProductSaveServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;

/**
 * @Author Rookie-6688
 * @Description
 * @Create 2021-03-28 21:45
 */
@RequestMapping("/search/save")
@RestController
@Slf4j
public class ElasticSaveController {


    @Resource
    ProductSaveServiceImpl productSaveServiceImpl;

    /**
     * 上架商品
     * @param skuEsModelList 要保存到 Es 的数据
     * @return
     */
    @PostMapping("/product")
    public R productStatusUp(@RequestBody List<SkuEsModel> skuEsModelList){
        try {
            productSaveServiceImpl.productStatusUp(skuEsModelList);
        } catch (IOException e) {
            log.error("商品上架发生异常"+e);
            return R.error(BizCodeEnum.PRODUCT_EXCEPTION.getCode(), BizCodeEnum.PRODUCT_EXCEPTION.getMsg());
        }
        return R.ok();
    }
}
